-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve find and package support #264
Improve find and package support #264
Conversation
This commit upgrades cmake to 2.8.12 to implement proper cmake `find_package` support using config and export file generation. Having this support enables users to use installed cppformat with a simple `find_package` call. Directly using a version from a build directory is also supported. main.cpp: ``` #include <cppformat/format.h> int main(int argc, char** argv) { for(int i = 0; i < argc; ++i) fmt::print("{}: {}\n",i,argv[i]); return 0; } ``` CMakeLists.txt: ``` cmake_minimum_required(VERSION 2.8.12) project(cppformat-test) find_package(cppformat REQUIRED) add_executable(cppformat-test "main.cpp") target_link_libraries(cppformat-test cppformat) ``` Configuring when cppformat is installed under `CMAKE_INSTALL_PREFIX`: `cmake <PATH_TO_TEST_SRC>` Configuring when cppformat is installed `ELSEWHERE`: `cmake -Dcppformat_DIR=<ELSEWHERE>/lib/cmake/cppformat <PATH_TO_TEST_SRC>` Configuring when cppformat is only built: `cmake -Dcppformat_DIR=<cppformat_BUILD_DIR> <PATH_TO_TEST_SRC>`
@@ -156,15 +156,52 @@ if (EXISTS .gitignore) | |||
|
|||
set(CPACK_SOURCE_GENERATOR ZIP) | |||
set(CPACK_SOURCE_IGNORE_FILES ${ignored_files}) | |||
set(CPACK_SOURCE_PACKAGE_FILE_NAME cppformat-${CPPFORMAT_VERSION}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove CPACK_SOURCE_PACKAGE_FILE_NAME
? It is used to set the correct source package name for distribution via website and releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced it with CPACK_PACKAGE_NAME
which is used for all generators, not only the source ZIP generator. Binary packages generated via make package
are now also named correctly.
However, it seems like I have missed that it now generates cppformat-<version>-Source.zip
instead of cppformat-<version>.zip
which definitely was not intended. Good catch!
Awesome, thanks for the contribution! I'm fine with increasing CMake version requirement to 2.8.12, but a newer version of CMake should be installed on Travis then, because the current version is 2.8.7 causing build failure: https://travis-ci.org/cppformat/cppformat/jobs/101819674 Also a minor comment regarding |
Great, you are welcome! I will address your comment and also have a look at the travis config to fix the CI issue. |
The use of `CPACK_PACKAGE_NAME` leads to `cppformat-<version>-Source.zip` as the name for the source package which is different from the expected `cppformat-<version>.zip`.
Improve find and package support
Merged with some minor, but opinionated =) changes in 22f6114 mostly to improve consistency with existing code. Thanks! |
Haha, consistency is definitely desired. =) Anyway, thank you for this great library and the fast and responsive processing of this pull request! |
Is it possible to use this in combination with ExternalProject_Add and/or git subtree? |
Not sure about |
I have not tested it right now but it should work with However, I want to stress that this is only true for cmake powered super builds which exclusively build external projects. If you want to use Hope this helps, |
@vitaut I just realized that your changes in 22f6114 changed the behavior when the library is used from the build tree. I previously copied the header into the build tree under The problem of this solution is that the required include paths are different. Including an installed version is done via We definitely should fix this discrepancy given that an application should not be aware of the way cppformat is built/installed. I see three possible solutions:
Suggestions? Regards, |
I'd go with one of the following options:
What do you think? |
I don't really like to force the user to mess with the include directories later on. The whole point of the export and find scripts is to get this right. I therefore would go with your second option. What do you think if we make the export, or at least the header copy, conditional but instead of introducing a new option we only do it for out-of-source builds? In-source builds would than behave like right now and out-of source builds would behave like in the original PR. |
Fair enough.
The point is to avoid copying headers for out-of-source builds, for in-source CMake might be clever enough not to do this by itself. Thinking more of it, I'm starting to lean towards your first option, namely moving the source files to a target_link_library(<target> cppformat) and it would set up include directories without the need to specify them manually. |
On 01/27/2016 05:22 PM, Victor Zverovich wrote:
Understood. I previously assumed that you just want to get rid of this
I am certain that this would be the cleanest solution. I was just
Right, this is exactly the nice behavior which you get from the new find I will give it a try tomorrow and submit a PR as soon as I have |
Great! BTW I think breakage can be avoided in most cases by having the following #include "cppformat/format.h"
#warning "Including format.h from the top-level directory is deprecated." or something like that. |
This PR upgrades cmake to 2.8.12 to implement proper cmake
find_package
support using config and export file generation. Having this support enables users to use installed cppformat with a simplefind_package
call. Directly using a version from a build directory is also supported. I think that this should also resolve #257.I am aware that upgrading cmake is maybe not desired. However, 2.8.12 is already pretty old and even available on the current (and soon superseded) Ubuntu 14.04 LTS. It should further be no problem to build a current CMake from source, especially for a software developer which wants to use cppformat.
Additionally, packaging in out of source build directories is now supported.
Regards,
niosHD
Usage Example:
main.cpp:
CMakeLists.txt:
Configuring when cppformat is installed under
CMAKE_INSTALL_PREFIX
:cmake <PATH_TO_TEST_SRC>
Configuring when cppformat is installed
ELSEWHERE
:cmake -Dcppformat_DIR=<ELSEWHERE>/lib/cmake/cppformat <PATH_TO_TEST_SRC>
Configuring when cppformat is only built:
cmake -Dcppformat_DIR=<cppformat_BUILD_DIR> <PATH_TO_TEST_SRC>